from django.db import models

##########$ User
class User (models.Model):
    email = models.EmailField(null=False,unique=True)
    tel = models.CharField(max_length=15,null=True)
    nom = models.CharField(max_length = 255,null=False)
    prenom = models.CharField(max_length = 255,null=False)
    region = models.ForeignKey("Region",null=True,blank=True)
    sexe = models.CharField(max_length=1,null=False)
    mot_de_passe = models.CharField(max_length=255,null=False)
    types = models.ManyToManyField("Type_User")

    def __unicode__(self):
        return u"%s" % self.nom
    
class Type_User (models.Model):
    nom = models.CharField(max_length = 255,null=False)
    descriptif = models.TextField()

    def __unicode__(self):
        return u"%s" % self.nom

class Type_Visiteur (models.Model):
    nom = models.CharField(max_length = 255,null=False)
    descriptif = models.TextField()
    types_event = models.ManyToManyField("Type_Event")
    types_lieu = models.ManyToManyField("Type_Lieu")

    def __unicode__(self):
        return u"%s" % self.nom

############ lieu
class Lieu (models.Model):
    nom = models.CharField(max_length = 255,null=False)
    position_lat = models.FloatField(null=False)
    position_lon = models.FloatField(null=False)
    descriptif = models.TextField()
    adresse = models.TextField()
    propose_par = models.ForeignKey("User",null=True)
    types = models.ManyToManyField("Type_Lieu")
    ville = models.ForeignKey("Ville")

    def __unicode__(self):
        return u"%s" % self.nom

class Type_Lieu (models.Model):
    nom = models.CharField(max_length = 255,null=False)
    descriptif = models.TextField()
    path_image = models.CharField(max_length = 255)

    def __unicode__(self):
        return u"%s" % self.nom

############ image 
class ImageLieu(models.Model):
    path_image = models.CharField(max_length = 255)
    lieu = models.ForeignKey("Lieu",null=True)

class ImageEvent(models.Model):
    path_image = models.CharField(max_length = 255)
    event = models.ForeignKey("Event",null=False)


########## Event
class Event (models.Model):
    nom = models.CharField(max_length = 255,null=False)
    descriptif = models.TextField()
    lieu = models.ForeignKey("Lieu",null=True)
    propose_par = models.ForeignKey("User",null=True)
    date_debut = models.DateTimeField()
    date_fin = models.DateTimeField()
    types = models.ManyToManyField("Type_Event")

    def __unicode__(self):
        return u"%s" % self.nom

class Type_Event (models.Model):
    nom = models.CharField(max_length = 255,null=False)
    descriptif = models.TextField()
    path_image = models.CharField(max_length = 255)

    def __unicode__(self):
        return u"%s" % self.nom


###### Region
class Region (models.Model):
    nom = models.CharField(max_length = 255,null=False)
    slug = models.SlugField(max_length = 255,null=False)
    descriptif = models.TextField()

    def __unicode__(self):
        return u"%s" % self.nom


class Departement(models.Model):
    region = models.ForeignKey("Region",null=True)
    code = models.CharField(max_length=3)
    nom = models.CharField(max_length = 255,null=False)

    def __unicode__(self):
        return u"%s" % self.nom


class Ville(models.Model):
    nom = models.CharField(max_length = 255,null=False)
    departement = models.ForeignKey("Departement",null=True)

    def __unicode__(self):
        return u"%s" % self.nom

#######$ Commentaires
class Score_Lieu (models.Model):
    score = models.IntegerField()
    lieu = models.ForeignKey("Lieu",null=False)
    user = models.ForeignKey("User")

    def __unicode__(self):
        return u"%d %s %s" % (self.score,self.lieu,self.user)

class Score_Event (models.Model):
    score = models.IntegerField()
    event = models.ForeignKey("Event",null=False)
    user = models.ForeignKey("User")

    def __unicode__(self):
        return u"%d %s %s" % (self.score,self.event,self.user)


